package top.lcm889.oj.leetcodeTop200;

/**
 * @author Coder-lcm
 * @date 2021/4/7
 */
public class LC204_计数质数 {
    public static int countPrimes(int n) {
        if (n < 2) {
            return 0;
        }else if (n == 2){
            return 1;
        }else{
            int count = 0;
            for(int i = 2; i <= n ; i++ ){
                boolean flag = true;
                for(int j = 2; j <= Math.sqrt(n); j++) {
                    if (n % j == 0) {
                        flag = false;
                        break;
                    }
                }
                count = count + (flag ? 1 : 0);
            }
            return count;
        }

    }

    public static void main(String[] args) {
        System.out.println(countPrimes(7));
    }
}
